<!DOCTYPE HTML>
<html lang="utf-8">
<head>
<meta charset="utf-8">
<title>驾车宝典-${loginMember.nickName!}的话题</title>
<link href="${ctx}/styles/group.css" rel="stylesheet" type="text/css">
<link href="${ctx}/styles/userPanel.css" rel="stylesheet" type="text/css">
<#include '/baseHead.ftl'>
<!--主要部分开始-->
<section id="main"><div class="bgA_01">
	
	<div class="userMailPanel_01"><!--这个功能块里的button标签可根据需要在 span button a 三种标签中调换-->
		<div class="menuField">
			<div class="btns">
				<a  class="btn btn1" title="点击撰写站内信"  href='${ctx}/message/newmessage'>写站内信</button>
			</div>
			<nav class="menu">
				<ul>
					<li><a href="${ctx}/message/receive" title="进入收件箱">收件箱</a></li>
					<li><a href="${ctx}/message/send" title="进入发件箱">发件箱</a></li>
					<li></li>
				</ul>
			</nav>
		</div>
		<div class="editField">
			<div class="title">
				<h2>写站内信</h2>
			</div>
			<div class="list">
				<dl>
					<dt>收件人：</dt>
					<dd><input  id="nickNames" type="text" class="txt" value="<#if nickName?exists && nickName!=''>${nickName!};</#if>" onblur="checkNickname();">
						<span style='color:gray'> &nbsp;多个用户请用";"隔开</span>
					</dd>
				</dl>
				<dl>
					<dt>主　题：</dt>
					<dd><input type="text" class="txt" value="" id="messageTitle" onkeyup='calRemain();'>
						<span style='color:gray'>还可输入 <strong id="remain">30</strong> 个字符</span>
					</dd>
				</dl>
				<dl>
					<dt>内　容：</dt>
					<dd><textarea class="textArea"  style="height:200px;"  id="messageCont" onkeyup='calRemain2();' ></textarea></dd>
				</dl>
			</div>
			<div class="btns">
				<span>已输入  <strong id="remain2">30</strong>  /500个字</span>
				<button class="btn btn1" title="点击发送" onclick='send();' style='background: url(${ctx}/images/btn_bg_12.jpg) 0 0 no-repeat;'></button>
			 <!--
			 	<button onclick='gohistory();' class="btn btn1" title="取消">取消</button>
			-->
			</div>
		</div>
	</div>
	
				
<#include '/commonFriendLink.ftl'>

</div></section>
<script>
	function send(){
	 var nickNames = $('#nickNames').val();
		 if ( nickNames.length == 0 ){
		 	alert("请输入收件人!");
		 	return ;
		 
		 }
	var messageTitle = $('#messageTitle').val();
	var messageCont = $('#messageCont').val();
	if (  messageTitle == "") {
		alert("请输入标题");
		return ;
	}
	if (  messageTitle.length  > 30) {
		alert("标题过长");
		return ;
	}
	if (  messageCont == "") {
		alert("请输入内容");
		return ;
	}
	if (  messageCont.length > 500 ) {
		alert("请输入内容");
		return ;
	}
	  $.ajax({
			 			type: "get",
						url: "${ctx}/member/checknicknames",
						beforeSend: function(XMLHttpRequest){
						//ShowLoading();
						},
						success: function(data, textStatus){
							var state = data.state;
							var desc = data.desc;
							if ( state ==  1 ){
							    $.ajax({
							 			type: "get",
										url: "${ctx}/message/sendaction",
										beforeSend: function(XMLHttpRequest){
										//ShowLoading();
										},
										success: function(data, textStatus){
											var state = data.state;
											var desc = data.desc;
											if ( state ==  1 ){
												alert("发送成功!");
												window.location.href  = '${ctx}/message/send';
											}else{
												alert ( desc );
											}
										},
										data:{
											nickNames:nickNames,
											messageCont:$('#messageCont').val(),
											messageTitle:$('#messageTitle').val()
										},
										dataType:'json'
									}
						 		)
							}else{
								alert ( desc );
							}
						},
						data:{
							nickNames:nickNames
						},
						dataType:'json'
					}
		 		)
	
	
	}
	function checkNickname(){
		 var nickNames = $('#nickNames').val();
		 if ( nickNames.length == 0 ){
		 	alert("请输入收件人!");
		 	return ;
		 
		 }
	     $.ajax({
			 			type: "get",
						url: "${ctx}/member/checknicknames",
						beforeSend: function(XMLHttpRequest){
						//ShowLoading();
						},
						success: function(data, textStatus){
							var state = data.state;
							var desc = data.desc;
							if ( state ==  1 ){
								
							
							}else{
								alert ( desc );
							}
						},
						data:{
							nickNames:nickNames
						},
						dataType:'json'
					}
		 		)
	
	}
	 function calRemain2(){
		if ( $('#messageCont').val().length > 500 ){
			$('#remain2').html("500");
			 $('#messageCont').val( $('#messageCont').val().substr(0,500) );
		}
		$('#remain2').html(  $('#messageCont').val().length);
	}
 function calRemain(){
		if ( $('#messageTitle').val().length > 30 ){
			$('#remain').html("0");
			 $('#messageTitle').val( $('#messageTitle').val().substr(0,30) );
		}
		$('#remain').html(30 -   $('#messageTitle').val().length);
	}
	var isCheckAll = true;
	function checkAll(){
		var messageIdCheckBoxs= 	document.getElementsByName("messageId");
			var messageIds = "";
			for ( var index = 0 ; index <messageIdCheckBoxs.length;index ++){
				var   messageIdCheckBox = messageIdCheckBoxs[index];
				messageIdCheckBox.checked = isCheckAll ;
			
			}
			if ( isCheckAll ) {
				isCheckAll = false;
			}else{
				isCheckAll = true;
			}
	}
	
	
	function getCheckedMessageId(){
		var messageIdCheckBoxs= 	document.getElementsByName("messageId");
		var messageIds = "";
		for ( var index = 0 ; index <messageIdCheckBoxs.length;index ++){
			var   messageIdCheckBox = messageIdCheckBoxs[index];
			if (   messageIdCheckBox.checked ){
			   if ( messageIds == ""){
			   		messageIds = messageIdCheckBox.value ;
			   		
			   }else{
			       messageIds = messageIds +","+ messageIdCheckBox.value;
			   }
			}
		}
		return messageIds;
	}
	function setIsRead(){
		  var checkedMessageIds  = getCheckedMessageId();
		  if ( checkedMessageIds == ""){
		  	
		  	alert("请勾选要操作的消息!");
		  	return ;
		  
		  }
		  if ( confirm("确认标识为已读吗?")){
			  $.ajax({
			 			type: "get",
						url: "${ctx}/message/setisread",
						beforeSend: function(XMLHttpRequest){
						//ShowLoading();
						},
						success: function(data, textStatus){
							window.location.reload();
						},
						data:{
							checkedMessageIds:checkedMessageIds
						},
						dataType:'json'
					}
		 		)
	 	}
	
	}
	function deleteMessage(){
	  var checkedMessageIds  = getCheckedMessageId();
		  if ( checkedMessageIds == ""){
		  	
		  	alert("请勾选要操作的消息!");
		  	return ;
		  
		  }
	    if ( confirm("确认删除消息吗?")){
		$.ajax({
			 			type: "get",
						url: "${ctx}/message/deletereceive",
						beforeSend: function(XMLHttpRequest){
						//ShowLoading();
						},
						success: function(data, textStatus){
								window.location.reload();
						},
						data:{
								checkedMessageIds:checkedMessageIds
						},
						dataType:'json'
					}
		 		)
		}
	}
	
	
</script>
<!--主要部分结束-->
<#include '/baseFoot.ftl'>